/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package comandaXM.utils;


import javax.swing.table.AbstractTableModel;


public class TableModel extends AbstractTableModel  {
    private String[] columnNames ;
    private Object[][] data ;
    public TableModel(String[] columnNames, Object[][]data){
        this.columnNames= columnNames;
        this.data= data;
    }
    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public int getRowCount() {
        try{
            return data.length;
        }catch  (NullPointerException nPE ){
            return 0;
        }                
    }

    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }

    @Override
    public Object getValueAt(int row, int col) {
        try{
            return data[row][col];
        }catch  (NullPointerException nPE ){
            return null; 
        }
        
    }

    @Override
    public Class getColumnClass(int c) {
        try{
            return getValueAt(0, c).getClass();
        }catch  (NullPointerException nPE ){
            return String.class; 
        }
        
    }

    /*
     * Don't need to implement this method unless your table's
     * editable.
     */
    @Override
    public boolean isCellEditable(int row, int col) {        
        return false; 
    }

    /*
     * Don't need to implement this method unless your table's
     * data can change.
     */
    @Override
    public void setValueAt(Object value, int row, int col) {        
        data[row][col] = value;        
        fireTableCellUpdated(row, col);
    }

   
    
}